<?php
session_start();
require_once ("../src/db/connectdatabase.php");
require_once ("../model/PartNumberToMoney.php");

function calculatorSalaryDealer($user, $datestart, $dateend) {
	$con = new ConnectDB();
	
	$sql = "SELECT amount3 FROM profilecustomer WHERE regis_email='".$user."' ";
	if($datestart != "") {
		$datestart = strtotime($datestart);
		$sql .= " AND datecreate>=".$datestart." ";
	}
	
	if($dateend != "") {
		$dateend = strtotime($dateend." 23:59");
		$sql .= " AND datecreate<=".$dateend." ";
	}
	
	return $con -> getvalueString($sql);
}

if(isset($_SESSION['taichinhondealer'])) {
	$email = $_SESSION['taichinhondealer'];
	if(isset($_POST['datestart']) && isset($_POST['dateend'])) {
		$datestart = trim($_POST['datestart']);
		$dateend = trim($_POST['dateend']);
		
		$arrsalary = calculatorSalaryDealer($email, $datestart, $dateend);
		$sumsalary = 0;
		foreach($arrsalary as $value) {
			$sumsalary += $value[0];
		}
		
		echo json_encode("Tổng thu nhập từ ngày ".$datestart." - ".$dateend."<br />".changnumbermoney($sumsalary)." VNĐ");
		return;
	}
}
echo json_encode("true");

?>